<?php
include('./library/conn.php');
$username=$_REQUEST['username'];
$password=$_REQUEST['password'];
$sele="select * from usar where username='$username'and password='$password'";
$res=$mysqli->query($sele);
$mysqli->close();
if($res->num_rows>0){
    $row=$res->fetch_assoc();
    $shop= $row['car'];
    setcookie('username',$row['username'],time()+3600*24,'/');
    // setcookie('shop',$row['car'],time()+3600*24,'/');
    setcookie('isLogined','true',time()+3600*24,'/');



  //cookie 解码
    echo "<script>
        
            let a=decodeURI('$shop');
            if(a){let b=a.replace(/%3A\+/g,':').replace(/%2C\+/g,',');
            let d=new Date();
            d.setDate(d.getDate() + 4);
            document.cookie = 'shop=' + b + ';expires=' + d + ';path=' + '/';}
            
            </script>";
    echo '<script>alert("登陆成功");</script>';
    echo '<script>location.href="../src/html/index.html"</script>';
}else{
    echo '<script>alert("用户名或密码错误");</script>';
    echo '<script>location.href="../src/html/login.html"</script>';

}


?>